import java.util.ArrayList;
import java.util.List;

/**
 * @author hewei
 * @version 1.0
 * @description: 1042. 不邻接植花
 * @date 2022/10/27 14:35
 */

public class GardenNoAdj {

    public int[] gardenNoAdj(int n, int[][] paths) {
        List<Integer>[] edge = new List[n];
        for (int i = 0; i < n; i++) {
            edge[i] = new ArrayList<>();
        }
        for (int[] path : paths) {
            int index = path[0] - 1;
            edge[index].add(path[1] - 1);
            edge[path[1] - 1].add(index);
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            List<Integer> list = edge[i];
            boolean[] flag = new boolean[5];
            for (Integer integer : list) {
                flag[ans[integer]] = true;
            }
            int temp = 1;
            while (flag[temp]) ++temp;
            ans[i] = temp;
        }
        return ans;
    }
}
